package com.xxxx.server.controller;


import com.xxxx.server.base.Page;
import com.xxxx.server.pojo.*;
import com.xxxx.server.service.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-09-07
 */
@RestController

    @RequestMapping("/employee/basic")
public class EmployeeController {


    @Resource
    private IEmployeeService employeeService;

    @Resource
    private INationService nationService;

    @Resource
    private IJoblevelService joblevelService;

    @Resource
    private IPositionService positionService;

    @Resource
    private IPoliticsStatusService politicsStatusService;

    @Resource
    private IDepartmentService departmentService;


    @ApiOperation("获取所有员工资料")
    @GetMapping("/")
    public Page getAll(@RequestParam("currentPage") Integer page, Integer size, String name){

        List<Employee> list = employeeService.queryAllEmp(page, size,name);
        return Page.respDataTotal(list,list.size());
    }

    @ApiOperation("打开添加员工，获取新的workid")
    @GetMapping("/maxWorkID")
    public RespBean maxWorkID(){
        String newId=employeeService.getNewId();
//        Employee employee = new Employee();
//        employee.setWorkID(newId);
        String newId1="00000"+newId;
        return RespBean.success("成功",newId1);
    }
    @ApiOperation("/添加员工")
    @PostMapping("/")
    public RespBean addEmp(@RequestBody Employee employee){
        boolean save = employeeService.save(employee);
        if (save){
            return RespBean.success("添加成功",employee);
        }else{
            return RespBean.error("添加失败");
        }
    }
    @ApiOperation("/删除员工")
    @DeleteMapping("/{id}")
    public RespBean deleteEmp(@PathVariable Integer id){
        Employee employee = employeeService.getById(id);
        if (employee==null||id==null){
            RespBean.error("待删除员工不存在");
        }
        boolean success = employeeService.removeById(id);
        if (success){
            return RespBean.success("删除成功");
        }else {
            return RespBean.error("删除失败");
        }
    }
    @ApiOperation("/修改员工")
    @PutMapping("/")
    public RespBean updateEmp(@RequestBody Employee employee){

        boolean success = employeeService.updateById(employee);
        if (success){
            return RespBean.success("修改成功",employee);
        }else {
            return RespBean.error("修改失败");
        }
    }

    @ApiOperation("/码云测试")
    @PutMapping("/mayun")
    public void mayun(){

    }


    @ApiOperation("获取所有民族信息")
    @GetMapping("/nations")
    public List<Nation> nations(){

//        List<String > list=employeeService.selectAllNations();

        List<Nation> list = nationService.list();
        return list;
    }

    @ApiOperation("获取所有职称")
    @GetMapping("/joblevels")
    public List<Joblevel> joblevels(){

        List<Joblevel> list = joblevelService.list();
        return list;

    }

    @ApiOperation("获取所有政治面貌")
    @GetMapping("/politicsstatus")
    public List<PoliticsStatus> politicsstatus(){
        List<PoliticsStatus> list = politicsStatusService.list();
        return list;
    }

    @ApiOperation("获取所有部门")
    @GetMapping("/deps")
    public List<Department> deps(){
        List<Department> list = departmentService.list();
        return list;
    }

    @ApiOperation("获取所有职位")
    @GetMapping("/positions")
    public List<Position> positions(){
        List<Position> list = positionService.list();
        return list;
    }

}
